package edu.ccut.saturn.component.loader.node;

/**
 * 用于解析logic组件配置文件中“事务开始”结点的加载类。
 * <p>继承了<code>NodeInfoLoader</code>,并实现了<code>loadNode</code>方法。<p>
 * 
 * @author 温建
 * @version 1.0 2008.8.18
 * 
 * @see <code>TransactionBeginNodeInfo</code>
 */
import java.util.ArrayList;
import java.util.List;

import org.dom4j.Element;
import org.osgi.framework.Bundle;

import edu.ccut.saturn.component.INodeInfo;
import edu.ccut.saturn.component.SaturnComponentException;
import edu.ccut.saturn.component.impl.node.TransactionBeginNodeInfo;

public class TransactionBeginNodeInfoLoader extends NodeInfoLoader {

	public static final String KEY_NODETYPE_TRANSACTION_BEGIN = "transactionBegin";

	@SuppressWarnings("unchecked")
	public List<INodeInfo> loadNode(Element root, Bundle bundle)
			throws SaturnComponentException {

		List<Element> elements = root.elements(KEY_NODETYPE_TRANSACTION_BEGIN);
		List<INodeInfo> transactionBeginNodeInfos = new ArrayList<INodeInfo>(
				elements.size());

		for (Element element : elements) {
			String id = element.attributeValue(KEY_NODE_ID).trim();
			String x = element.attributeValue(KEY_NODE_X).trim();
			String y = element.attributeValue(KEY_NODE_Y).trim();
			String next = element.attributeValue(KEY_NODE_NEXT).trim();
			String name = element.elementTextTrim(KEY_NODE_NAME);
			String description = element.elementTextTrim(KEY_NODE_DESCRIPTION);
			
			logger.debug("  load transaction begin node id = \"" + id 
					+ "\" node name = \"" + name + "\" description = \""
					+ description + "\" nextId = \"" + next
					+ "\"");

			TransactionBeginNodeInfo transactionBegin = new TransactionBeginNodeInfo(
					id, name, description, next, x, y);

			transactionBeginNodeInfos.add(transactionBegin);
		}
		return transactionBeginNodeInfos;
	}

}
